using Abp.Authorization;
using Abp.Localization;
using Abp.MultiTenancy;
using Mt.Site.Core.Authorization;

namespace Mt.Site.Core.SiteMaps
{
    public class SiteMapPermissionProvider: AuthorizationProvider
    {
        public override void SetPermissions(IPermissionDefinitionContext context)
        {
            var pages = context.GetPermissionOrNull(AppPermissions.Pages) ?? context.CreatePermission(AppPermissions.Pages, L("Pages"));
            pages.CreateChildPermission(SiteMapPermissions.Pages_Manage_SiteMap, L("SiteMaps"), multiTenancySides: MultiTenancySides.Tenant);

            pages.CreateChildPermission(SiteMapPermissions.Pages_Manage_Robots, new FixedLocalizableString("Robots-txt"), multiTenancySides: MultiTenancySides.Tenant);
        }

        private static ILocalizableString L(string name)
        {
            return new LocalizableString(name, MtSiteConsts.LocalizationSourceName_Permissions);
        }
    }
}
